<template>
	<div class="left-box">
		<div class="heade-wrapper">
			<a-input-search
				v-model="searchInfo"
				class="last-input-box"
				:placeholder="this.$i18n('selectPeople.input',this.$i18n('selectPeople.bussinessOraganization.account.label'))"
				@keyup.enter="onSearch"
			/>
		</div>
		<div class="content-wrapper">
			<scroll-list
				ref="accountList"
				:checkAllShow="false"
				:singleAndMult="false"
				:firstLoadSearch="firstLoadSearch"
				iconType="cap-icon-alternative-company"
				command="businessOrgList"
				panel="BusinessAccount"
			/>
		</div>
	</div>
</template>

<script>
import scrollList from '@/components/scrollList';

export default {
	name: 'BusinessAccount',
	components: { scrollList },
	inject: ['app'],
	data() {
		return {
			searchTypeOptions: [],
			selectedUnitId: '',
			searchParams: {},
			searchInfo: '',
			firstLoadSearch: false
		};
	},
	watch: {},
	computed: {
		orgSelect() {
			return this.app().orgSelect;
		}
	},
	methods: {
		initProps: function () {
			this.selectedUnitId = '';
			this.searchParams = {};
		},

		/*
		 * 切换当前机构已选项
		 */
		onChangeAccount: function (ret) {
			console.log('ret: ', ret);
			this.initProps();
			this.selectedUnitId = ret.id;
			this.searchParams = { accountId: ret.id };
			this.onSearch();
		},

		/*
		 *   搜索
		 */
		onSearch: function () {
			this.searchParams = {};
			this.searchParams.accountId = this.selectedUnitId;
			if (this.searchInfo != '') {
				this.searchParams.keyword = this.searchInfo;
			}
			this.$refs.accountList.search(this.searchParams);
		},
		/**
		 * 初始化加载数据
		*/
		onLoadData(val) {
			this.selectedUnitId = val;
			this.firstLoadSearch = true;
			this.onSearch();
		}
	},

	beforeMount() {
	},
	mounted() {
		let accountId = '';
		if (
			Object.prototype.hasOwnProperty.call(this.app().switchAfterUnit, 'id')
		) {
			accountId = this.app().switchAfterUnit.id;
		} else {
			accountId = this.orgSelect.defaultAccountId;
		}
		// this.selectedUnitId = accountId;
		// this.firstLoadSearch = true;
		// this.onSearch();
		this.onLoadData(accountId);
	},
	activated() {
		const { id: accountId } = this.app().switchAfterUnit;
		if (this.$isChangeAccount(this, accountId)) {
			this.onLoadData(accountId);
		}
	}
};
</script>

<style lang="scss" scoped>
</style>
